#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <utility>

std::vector<std::pair<int, int>> ans; // 2^int and 3^int

int const maxn = 50;
long long pow3[maxn];
long long n;

int get(long long n)
{
    int ret = 3 - (n % 3);
    for (; ((long long)(1) << ret) <= n; ret += 2);
    return ret - 2;
}

void calc(long long n, int count_three)
{
    if (n == 1) {
        ans.push_back(std::make_pair(0, count_three));
        return;
    }
    if (n == 0) {
        return;
    }
    for (; !(n % 3); ) count_three++, n /= 3;
    int tmp = get(n);
    calc(n - ((long long)(1) << tmp), count_three);
    ans.push_back(std::make_pair(tmp, count_three));
}

void init()
{
    pow3[0] = 1;
    for (int i = 1; i <= 39; i++) pow3[i] = pow3[i - 1] * 3;
}

int main()
{
    std::ifstream fin{"distribution.in"};
    std::ofstream fout{"distribution.out"};

    init();

    int T; fin >> T;
    while (T--) {
        fin >> n;
        ans.clear();
        calc(n, 0);

        fout << ans.size() << '\n';
        for (auto i : ans)
            fout << (((long long)(1) << i.first) * pow3[i.second]) << ' ';
        fout << '\n';
    }
}

